package o;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.text.TextUtils;
import androidx.core.app.NotificationCompat.b;
import androidx.core.app.NotificationCompat.d;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appmarket.service.keyappupdate.bean.KeyAppDetail;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import o.ewm.e;
import o.ewm.n;

public class dqi extends dpn<Boolean, Boolean> {
    protected /* synthetic */ void ˏ(Context context, Object obj, Object obj2) throws InterruptedException {
        ॱ(context, (Boolean) obj, (Boolean) obj2);
    }

    protected /* synthetic */ Object ॱ(Context context) throws InterruptedException {
        return ˋ(context);
    }

    public dqi() {
        this.ˊ = "KeyUpdateTask";
    }

    public static void ˏ(Context context, ApkUpgradeInfo apkUpgradeInfo, Bitmap bitmap, String str) {
        String ˏ = dqb.ˏ();
        int ˋ = dss.ॱ().ˋ(ˏ);
        if (dss.ॱ().ˋॱ() <= ˋ) {
            Logger.ˎ(str, "up to MAX Update notify size,do not show key app notify.name:" + apkUpgradeInfo.ˊ() + ",id:" + apkUpgradeInfo.ॱ());
            return;
        }
        CharSequence string;
        CharSequence string2;
        Logger.ˎ(str, "show key app name:" + apkUpgradeInfo.ˊ() + ",id:" + apkUpgradeInfo.ॱ());
        KeyAppDetail keyAppDetail = new KeyAppDetail();
        keyAppDetail.ˏ(apkUpgradeInfo.ᐝ());
        keyAppDetail.ˎ(apkUpgradeInfo.ʿ());
        ebo.ॱ().ˏ(keyAppDetail);
        String ˎ = ˎ(apkUpgradeInfo.ʻ());
        String ˎ2 = ˎ(apkUpgradeInfo.ʽ());
        if (ˎ.split("\\.")[0].trim().equals(ˎ2.split("\\.")[0].trim())) {
            string = context.getString(n.Ꞌ, new Object[]{apkUpgradeInfo.ˊ()});
        } else {
            string = context.getString(n.﹍, new Object[]{apkUpgradeInfo.ˊ()});
        }
        if (apkUpgradeInfo.ʼ() > 0) {
            string2 = context.getString(n.ꞌˊ, new Object[]{ˎ, ˎ2, epw.ˊ(apkUpgradeInfo.ʼ()), epw.ˊ(apkUpgradeInfo.ʻॱ() - apkUpgradeInfo.ʼ())});
        } else {
            string2 = context.getString(n.ꞌᐝ, new Object[]{ˎ, ˎ2, epw.ˊ(apkUpgradeInfo.ʻॱ())});
        }
        d dVar = new d(context);
        dVar.ˏ(string);
        dVar.ˊ(string2);
        dVar.ˏ(true);
        dVar.ˊ(false);
        float ˊ = dkk.ˊ();
        dVar.ˎ(eqx.ˏ(bitmap, (double) ˊ, (double) ˊ));
        dVar.ˊ(e.ॱ);
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        Request request = new Request();
        request.ˋ(apkUpgradeInfo.ˊᐝ());
        request.ˏ(context.getString(n.ㆍ));
        request.ॱ(KeyAndValue.NUMBER_01);
        request.ˊ(true);
        appDetailActivityProtocol.ˏ(request);
        Intent ॱ = new cjm("appdetail.activity", appDetailActivityProtocol).ॱ(context);
        ॱ.putExtra("activity_open_from_notification_flag", true);
        PendingIntent activity = PendingIntent.getActivity(context, 1020, ॱ, 268435456);
        PendingIntent ॱ2 = dss.ॱ().ॱ(context, apkUpgradeInfo.ᐝ());
        if (!TextUtils.isEmpty(apkUpgradeInfo.ʼॱ())) {
            string2 = string2 + "\n" + apkUpgradeInfo.ʼॱ();
        }
        dVar.ˊ(new b().ˏ(string2));
        dVar.ॱ(e.ᐝˋ, context.getString(n.ﹺॱ), ॱ2);
        dVar.ˎ(activity);
        dVar.ˋ(true);
        dss.ॱ().ˏ(context, apkUpgradeInfo.ᐝ(), dVar.ˊ(), ˏ, ˋ);
    }

    private static String ˎ(String str) {
        if (str == null) {
            return "";
        }
        return !str.toLowerCase(Locale.US).startsWith("v") ? "V" + str : str;
    }

    protected Boolean ˋ(Context context) {
        if (dss.ॱ().ˊ()) {
            Logger.ˎ(this.ˊ, "do not check key app update,Update Do Not Disturb is open.");
            return Boolean.valueOf(false);
        } else if (doo.ʼ(ContentManager.getInstant().getContext()) == 1 && dss.ॱ().ˎ()) {
            Logger.ˎ(this.ˊ, "do not check key app update,netType is wifi,and PreUpdate has been opend.");
            return Boolean.valueOf(false);
        } else {
            long ʼ = dss.ॱ().ʼ();
            if (System.currentTimeMillis() - ʼ < dss.ॱ().ͺ()) {
                Logger.ˎ(this.ˊ, "do not check key app update,last key update notify showed In 2 hours." + ʼ);
                return Boolean.valueOf(false);
            }
            ʼ = dss.ॱ().ˋ();
            if (System.currentTimeMillis() - ʼ < dss.ॱ().ͺ()) {
                Logger.ˎ(this.ˊ, "do not check key app update,last app update notify showed In 2 hours." + ʼ);
                return Boolean.valueOf(false);
            }
            if (dss.ॱ().ˋॱ() > dss.ॱ().ˋ(dqb.ˏ())) {
                return Boolean.valueOf(true);
            }
            Logger.ˎ(this.ˊ, "do not check key app update,today update notify size up to max size.");
            return Boolean.valueOf(false);
        }
    }

    protected Boolean ˋ(Context context, Boolean bool) {
        if (!bool.booleanValue()) {
            return Boolean.valueOf(false);
        }
        Logger.ˎ("ScheduleRepeatService", this.ˊ + " execute");
        return Boolean.valueOf(ˎ(context));
    }

    protected void ॱ(Context context, Boolean bool, Boolean bool2) {
        if (bool2.booleanValue()) {
            euf.ˎ().ˎ("lastTime_keyUpdate", System.currentTimeMillis());
        }
    }

    private boolean ˎ(Context context) {
        List<ApkUpgradeInfo> ˎ = dss.ॱ().ˎ(true, 1);
        List arrayList = new ArrayList();
        if (ˎ.size() > 0) {
            for (ApkUpgradeInfo apkUpgradeInfo : ˎ) {
                if (apkUpgradeInfo != null && 1 == apkUpgradeInfo.ˎˎ()) {
                    if (ebo.ॱ().ˏ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ʿ()).size() <= 0) {
                        arrayList.add(apkUpgradeInfo);
                    } else if (Logger.ˎ()) {
                        Logger.ˏ("ScheduleRepeatService", this.ˊ + " key app has showed notify:pkg:" + apkUpgradeInfo.ᐝ() + ",versionCode:" + apkUpgradeInfo.ʿ());
                    }
                }
            }
            if (!dhq.ॱ().ˎ()) {
                return false;
            }
        }
        if (arrayList.size() <= 0) {
            return false;
        }
        Collections.sort(arrayList, new ApkUpgradeInfo());
        ˏ(context, (ApkUpgradeInfo) arrayList.get(0));
        return true;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void ˏ(android.content.Context r7, com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo r8) {
        /*
        r6 = this;
        r1 = r7.getPackageManager();	 Catch:{ Exception -> 0x0045 }
        r0 = r8.ᐝ();	 Catch:{ Exception -> 0x0045 }
        r2 = 0;
        r2 = r1.getPackageInfo(r0, r2);	 Catch:{ Exception -> 0x0045 }
        r0 = 0;
        r2 = r2.applicationInfo;	 Catch:{ OutOfMemoryError -> 0x003c, Exception -> 0x004e }
        r1 = r1.getApplicationIcon(r2);	 Catch:{ OutOfMemoryError -> 0x003c, Exception -> 0x004e }
        r0 = o.ern.ॱ(r1);	 Catch:{ OutOfMemoryError -> 0x003c, Exception -> 0x004e }
        r1 = 0;
        r0 = o.ern.ˏ(r7, r0, r1);	 Catch:{ OutOfMemoryError -> 0x003c, Exception -> 0x0076 }
    L_0x001d:
        if (r0 != 0) goto L_0x0070;
    L_0x001f:
        r0 = r6.ˊ;	 Catch:{ Exception -> 0x0045 }
        r1 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0045 }
        r1.<init>();	 Catch:{ Exception -> 0x0045 }
        r2 = "get icon failed,break show notification! packageName:";
        r1 = r1.append(r2);	 Catch:{ Exception -> 0x0045 }
        r2 = r8.ᐝ();	 Catch:{ Exception -> 0x0045 }
        r1 = r1.append(r2);	 Catch:{ Exception -> 0x0045 }
        r1 = r1.toString();	 Catch:{ Exception -> 0x0045 }
        o.dna.ˊ(r0, r1);	 Catch:{ Exception -> 0x0045 }
    L_0x003b:
        return;
    L_0x003c:
        r1 = move-exception;
        r1 = r6.ˊ;	 Catch:{ Exception -> 0x0045 }
        r2 = "prepareDataIcon(...) ";
        o.dna.ˊ(r1, r2);	 Catch:{ Exception -> 0x0045 }
        goto L_0x001d;
    L_0x0045:
        r0 = move-exception;
        r1 = r6.ˊ;
        r2 = "prepareDataIcon error!!";
        o.dna.ˋ(r1, r2, r0);
        goto L_0x003b;
    L_0x004e:
        r1 = move-exception;
        r5 = r1;
        r1 = r0;
        r0 = r5;
    L_0x0052:
        r2 = r6.ˊ;	 Catch:{ Exception -> 0x0045 }
        r3 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x0045 }
        r3.<init>();	 Catch:{ Exception -> 0x0045 }
        r4 = "prepareDataIcon(...) ";
        r3 = r3.append(r4);	 Catch:{ Exception -> 0x0045 }
        r0 = r0.toString();	 Catch:{ Exception -> 0x0045 }
        r0 = r3.append(r0);	 Catch:{ Exception -> 0x0045 }
        r0 = r0.toString();	 Catch:{ Exception -> 0x0045 }
        o.dna.ˋ(r2, r0);	 Catch:{ Exception -> 0x0045 }
        r0 = r1;
        goto L_0x001d;
    L_0x0070:
        r1 = r6.ˊ;	 Catch:{ Exception -> 0x0045 }
        ˏ(r7, r8, r0, r1);	 Catch:{ Exception -> 0x0045 }
        goto L_0x003b;
    L_0x0076:
        r1 = move-exception;
        r5 = r1;
        r1 = r0;
        r0 = r5;
        goto L_0x0052;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.dqi.ˏ(android.content.Context, com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo):void");
    }
}
